﻿using Microsoft.Extensions.Configuration;
using System.IO;

namespace SingleBlog.Framework
{
    /// <summary>
    /// 表示 SingleBlog 的配置器。会将程序必要配置进行统一处理。
    /// </summary>
    public class SingleBlogConfigurationBuilder
    {
        private readonly IConfigurationBuilder _builder;
        /// <summary>
        /// 初始化 <see cref="SingleBlogConfigurationBuilder"/> 类的新实例。
        /// </summary>
        /// <param name="builder">配置建造者的实例。</param>
        public SingleBlogConfigurationBuilder(IConfigurationBuilder builder)
        {
            _builder = builder;
        }

        /// <summary>
        /// 获取配置。
        /// </summary>
        /// <returns></returns>
        public IConfiguration GetConfiguration()
        {
            _builder
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile($"ConfigFiles/appsettings.json")
                .AddJsonFile($"ConfigFiles/SingleBlog.config.json")
                ;
            return _builder.Build();
        }
    }
}
